<template>
  <div id="map" style="height: 600px"></div>
</template>

<script>
import worldmapjson from "../../assets/scss/worldgeo.json";
import { request } from "../network";

export default {
  components: {
    
  },
  data() {
    return {
      map: null,
      bb: '',
      newreportdata_10:[],
      linedata:[//攻击路径坐标

          
            ],
      aptcountry:Array,
      mappoint:{"Angola":[17.87,-11.20],
    "Afghanistan":[67.71,33.94],
    "Albania":[20.17,41.15],
    "Algeria":[1.66,28.03],
    "Andorra":[1.52,42.51],
    "Anguilla":[-63.07,18.22],
    "Argentina":[-63.62,-38.42],
    "Armenia":[45.04,40.07],
    "Ascension":[-90.94,30.20],
    "Australia":[133.78,-25.27],
    "Austria":[14.55,47.52],
    "Azerbaijan":[47.58,40.14],
    "Britain":[-3.435973,55.378051],
    "Bahamas":[-77.40,25.03],
    "Bahrain":[50.56,26.07],
    "Bangladesh":[90.36,23.68],
    "Barbados":[-59.54,13.19],
    "Belarus":[27.95,53.71],
    "Belgium":[4.47,50.50],
    "Belize":[-88.50,17.19],
    "Benin":[2.32,9.31],
    "Bermuda Is":[-64.75,32.31],
    "Bolivia":[-63.59,-16.29],
    "Botswana":[24.68,-22.33],
    "Brazil":[-51.93,-14.24],
    "Brunei":[114.73,4.54],
    "Bulgaria":[25.49,42.73],
    "Burkina-faso":[-1.56,12.24],
    "Burma":[95.96,21.92],
    "Burundi":[29.92,-3.37],
    "Cameroon":[12.35,7.37],
    "Canada":[-106.35,56.13],
    "Cayman Is":[-117.64,33.64],
    "Central African Republic":[20.94,6.61],
    "Chad":[18.73,15.45],
    "Chile":[-71.54,-35.68],
    "China":[104.20,35.86],
    "Colombia":[-74.30,4.57],
    "Congo":[15.83,-0.23],
    "Cook Is":[-90.49,47.61],
    "Costa Rica":[-83.75,9.75],
    "Croatia":[15.2,45.1],
    "Cuba":[-77.78,21.52],
    "Cyprus":[33.43,35.13],
    "Czech Republic":[15.47,49.82],
    "Denmark":[9.50,56.26],
    "Djibouti":[42.59,11.83],
    "Dominica Rep":[-0.19,51.52],
    "Ecuador":[-78.18,-1.83],
    "Egypt":[30.80,26.82],
    "EI Salvador":[-88.90,13.79],
    "Estonia":[25.01,58.60],
    "Ethiopia":[40.49,9.15],
    "Fiji":[178.07,-17.71],
    "Finland":[25.75,61.92],
    "France":[2.21,46.23],
    "French Guiana":[-53.13,3.93],
    "Gabon":[11.61,-0.80],
    "Gambia":[-15.31,13.44],
    "Georgia":[-82.90,32.17],
    "Germany":[10.45,51.17],
    "Ghana":[-1.02,7.95],
    "Gibraltar":[-5.35,36.14],
    "Greece":[21.82,39.07],
    "Grenada":[-61.68,12.12],
    "Guam":[144.79,13.44],
    "Guatemala":[-90.23,15.78],
    "Guinea":[-9.70,9.95],
    "Guyana":[-58.93,4.86],
    "Haiti":[-72.29,18.97],
    "Honduras":[-86.24,15.20],
    "Hong Kong":[114.11,22.40],
    "Hungary":[19.50,47.16],
    "Iceland":[-19.02,64.96],
    "India":[78.96,20.59],
    "Indonesia":[113.92,-0.79],
    "Iran":[53.69,32.43],
    "Iraq":[43.68,33.22],
    "Ireland":[-8.24,53.41],
    "Israel":[34.85,31.05],
    "Italy":[12.57,41.87],
    "Ivory Coast":[-5.55,7.54],
    "Jamaica":[-77.30,18.11],
    "Japan":[138.25,36.20],
    "Jordan":[36.24,30.59],
    "Kampuchea":[105.46,12.00],
    "Kazakstan":[66.92,48.02],
    "Kenya":[37.91,-0.02],
    "Korea":[127.98,37.66],
    "Kuwait":[47.48,29.31],
    "Kyrgyzstan":[74.77,41.20],
    "Laos":[102.50,19.86],
    "Latvia":[24.60,56.88],
    "Lebanon":[35.86,33.85],
    "Lesotho":[28.23,-29.61],
    "Liberia":[-9.43,6.43],
    "Libya":[17.23,26.34],
    "Liechtenstein":[9.56,47.17],
    "Lithuania":[23.88,55.17],
    "Luxembourg":[6.13,49.82],
    "Macao":[113.54,22.20],
    "Madagascar":[46.87,-18.77],
    "Malawi":[34.30,-13.25],
    "Malaysia":[101.98,4.21],
    "Maldives":[73.54,1.98],
    "Mali":[-4.00,17.57],
    "Malta":[14.38,35.94],
    "Mariana Is":[-43.41,-20.37],
    "Martinique":[-61.02,14.64],
    "Mauritius":[57.55,-20.35],
    "Mexico":[-102.55,23.63],
    "Monaco":[7.42,43.74],
    "Mongolia":[103.85,46.86],
    "Montserrat Is":[-62.19,16.74],
    "Morocco":[-7.09,31.79],
    "Mozambique":[35.53,-18.67],
    "Namibia":[18.49,-22.96],
    "Nauru":[166.93,-0.52],
    "Nepal":[84.12,28.39],
    "Netheriands Antilles":[-68.26,12.20],
    "Netherlands":[5.29,52.13],
    "New Zealand":[174.89,-40.90],
    "Nicaragua":[-85.21,12.87],
    "Niger":[8.08,17.61],
    "Nigeria":[8.68,9.08],
    "North Korea":[127.51,40.34],
    "Norway":[8.47,60.47],
    "Oman":[55.98,21.47],
    "Pakistan":[69.35,30.38],
    "Panama":[-80.78,8.54],
    "Papua New Cuinea":[143.96,-6.31],
    "Paraguay":[-58.44,-23.44],
    "Peru":[-75.02,-9.19],
    "Philippines":[121.77,12.88],
    "Poland":[19.15,51.92],
    "French Polynesia":[-149.41,-17.68],
    "Portugal":[-8.22,39.40],
    "Puerto Rico":[-66.59,18.22],
    "Qatar":[51.18,25.35],
    "Reunion":[55.54,-21.12],
    "Romania":[24.97,45.94],
    "Russia":[105.32,61.52],
    "Saint Lueia":[-60.98,13.91],
    "Saint Vincent":[7.64,45.75],
    "Samoa Eastern":[-121.83,37.35],
    "Samoa Western":[-124.15,40.80],
    "San Marino":[12.46,43.94],
    "Sao Tome and Principe":[6.61,0.19],
    "Saudi Arabia":[45.08,23.89],
    "Senegal":[-14.45,14.50],
    "Seychelles":[55.49,-4.68],
    "Sierra Leone":[-11.78,8.46],
    "Singapore":[103.82,1.35],
    "Slovakia":[19.70,48.67],
    "Slovenia":[15.00,46.15],
    "Solomon Is":[-97.37,38.92],
    "Somali":[46.20,5.15],
    "South Africa":[22.94,-30.56],
    "Spain":[-3.75,40.46],
    "Sri Lanka":[80.77,7.87],
    "St.Lucia":[-60.98,13.91],
    "St.Vincent":[-91.06,29.99],
    "Sudan":[30.22,12.86],
    "Suriname":[-56.03,3.92],
    "Swaziland":[31.47,-26.52],
    "Sweden":[18.64,60.13],
    "Switzerland":[8.23,46.82],
    "Syria":[39.00,34.80],
    "Taiwan":[120.96,23.70],
    "Tajikstan":[71.28,38.86],
    "Tanzania": [34.89, -6.37],
    "Thailand": [100.99, 15.87],
    "Togo": [0.82, 8.62],
    "Tonga": [-175.20, -21.18],
    "Trinidad and Tobago": [-61.22, 10.69],
    "Tunisia": [9.54, 33.89],
    "Turkey": [35.24, 38.96],
    "Turkmenistan": [59.56, 38.97],
    "Uganda": [32.29, 1.37],
    "Ukraine": [31.17, 48.38],
    "United Arab Emirates": [53.85, 23.42],
    "United Kingdom": [-3.44, 55.38],
    "United States": [-95.71, 37.09],
    "Uruguay": [-55.77, -32.52],
    "Uzbekistan": [64.59, 41.38],
    "Venezuela": [-66.59, 6.42],
    "Vietnam": [108.28, 14.06],
    "Yemen": [48.52, 15.55],
    "Yugoslavia": [121.02, 14.48],
    "Zimbabwe": [29.15, -19.02],
    "Zaire": [21.76, -4.04],
    "Zambia": [27.85, -13.13]
    },
    nammap:{
      "Afghanistan": "阿富汗",
      "Angola": "安哥拉",
      "Albania": "阿尔巴尼亚",
      "Algeria": "阿尔及利亚",
      "Argentina": "阿根廷",
      "Armenia": "亚美尼亚",
      "Australia": "澳大利亚",
      "Austria": "奥地利",
      "Azerbaijan": "阿塞拜疆",
      "Britain":"英国",
      "Bahamas": "巴哈马",
      "Bangladesh": "孟加拉国",
      "Belgium": "比利时",
      "Benin": "贝宁",
      "Burkina Faso": "布基纳法索",
      "Burundi": "布隆迪",
      "Bulgaria": "保加利亚",
      "Bosnia and Herz.": "波斯尼亚和黑塞哥维那",
      "Belarus": "白俄罗斯",
      "Belize": "伯利兹",
      "Bermuda": "百慕大群岛",
      "Bolivia": "玻利维亚",
      "Brazil": "巴西",
      "Brunei": "文莱",
      "Bhutan": "不丹",
      "Botswana": "博茨瓦纳",
      "Cambodia": "柬埔寨",
      "Cameroon": "喀麦隆",
      "Canada": "加拿大",
      "Central African Rep.": "中非共和国",
      "Chad": "乍得",
      "Chile": "智利",
      "China": "中国",
      "Taiwan":"中国台湾",
      "Colombia": "哥伦比亚",
      "Congo": "刚果",
      "Costa Rica": "哥斯达黎加",
      "Côte d'Ivoire": "科特迪瓦",
      "Croatia": "克罗地亚",
      "Cuba": "古巴",
      "Cyprus": "塞浦路斯",
      "Czech Rep.": "捷克共和国",
      "Dem. Rep. Korea": "韩国",
      "Dem. Rep. Congo": "民主刚果",
      "Denmark": "丹麦",
      "Djibouti": "吉布提",
      "Dominican Rep.": "多米尼加共和国",
      "Ecuador": "厄瓜多尔",
      "Egypt": "埃及",
      "El Salvador": "萨尔瓦多",
      "Eq. Guinea": "赤道几内亚",
      "Eritrea": "厄立特里亚",
      "Estonia": "爱沙尼亚",
      "Ethiopia": "埃塞俄比亚",
      "Falkland Is.": "福克兰群岛",
      "Fiji": "斐济",
      "Finland": "芬兰",
      "France": "法国",
      "French Guiana": "法属圭亚那",
      "Fr. S. Antarctic Lands": "法属南部领地",
      "Gabon": "加蓬",
      "Gambia": "冈比亚",
      "Germany": "德国",
      "Georgia": "佐治亚州",
      "Ghana": "加纳",
      "Greece": "希腊",
      "Greenland": "格陵兰",
      "Guatemala": "危地马拉",
      "Guinea": "几内亚",
      "Guinea-Bissau": "几内亚比绍",
      "Guyana": "圭亚那",
      "Haiti": "海地",
      "Heard I. and McDonald Is.": "赫德岛和麦克唐纳群岛",
      "Honduras": "洪都拉斯",
      "Hungary": "匈牙利",
      "Iceland": "冰岛",
      "India": "印度",
      "Indonesia": "印度尼西亚",
      "Iran": "伊朗",
      "Iraq": "伊拉克",
      "Ireland": "爱尔兰",
      "Israel": "以色列",
      "Italy": "意大利",
      "Ivory Coast": "象牙海岸",
      "Jamaica": "牙买加",
      "Japan": "日本",
      "Jordan": "乔丹",
      "Kashmir": "克什米尔",
      "Kazakhstan": "哈萨克斯坦",
      "Kenya": "肯尼亚",
      "Kosovo": "科索沃",
      "Kuwait": "科威特",
      "Kyrgyzstan": "吉尔吉斯斯坦",
      "Laos": "老挝",
      "Lao PDR": "老挝人民民主共和国",
      "Latvia": "拉脱维亚",
      "Lebanon": "黎巴嫩",
      "Lesotho": "莱索托",
      "Liberia": "利比里亚",
      "Libya": "利比亚",
      "Lithuania": "立陶宛",
      "Luxembourg": "卢森堡",
      "Madagascar": "马达加斯加",
      "Macedonia": "马其顿",
      "Malawi": "马拉维",
      "Malaysia": "马来西亚",
      "Mali": "马里",
      "Mauritania": "毛里塔尼亚",
      "Mexico": "墨西哥",
      "Moldova": "摩尔多瓦",
      "Mongolia": "蒙古",
      "Montenegro": "黑山",
      "Morocco": "摩洛哥",
      "Mozambique": "莫桑比克",
      "Myanmar": "缅甸",
      "Namibia": "纳米比亚",
      "Netherlands": "荷兰",
      "New Caledonia": "新喀里多尼亚",
      "New Zealand": "新西兰",
      "Nepal": "尼泊尔",
      "Nicaragua": "尼加拉瓜",
      "Niger": "尼日尔",
      "Nigeria": "尼日利亚",
      "Korea": "朝鲜",
      "Northern Cyprus": "北塞浦路斯",
      "Norway": "挪威",
      "Oman": "阿曼",
      "Pakistan": "巴基斯坦",
      "Panama": "巴拿马",
      "Papua New Guinea": "巴布亚新几内亚",
      "Paraguay": "巴拉圭",
      "Peru": "秘鲁",
      "Republic of the Congo": "刚果共和国",
      "Philippines": "菲律宾",
      "Poland": "波兰",
      "Portugal": "葡萄牙",
      "Puerto Rico": "波多黎各",
      "Qatar": "卡塔尔",
      "Republic of Seychelles": "塞舌尔共和国",
      "Romania": "罗马尼亚",
      "Russia": "俄罗斯",
      "Singapore": "新加坡",
      "Rwanda": "卢旺达",
      "Samoa": "萨摩亚",
      "Saudi Arabia": "沙特阿拉伯",
      "Senegal": "塞内加尔",
      "Serbia": "塞尔维亚",
      "Sierra Leone": "塞拉利昂",
      "Slovakia": "斯洛伐克",
      "Slovenia": "斯洛文尼亚",
      "Solomon Is.": "所罗门群岛",
      "Somaliland": "索马里兰",
      "Somalia": "索马里",
      "South Africa": "南非",
      "S. Geo. and S. Sandw. Is.": "南乔治亚和南桑德威奇群岛",
      "S. Sudan": "南苏丹",
      "Spain": "西班牙",
      "Sri Lanka": "斯里兰卡",
      "Sudan": "苏丹",
      "Suriname": "苏里南",
      "Swaziland": "斯威士兰",
      "Sweden": "瑞典",
      "Switzerland": "瑞士",
      "Syria": "叙利亚",
      "Tajikistan": "塔吉克斯坦",
      "Tanzania": "坦桑尼亚",
      "Thailand": "泰国",
      "The Kingdom of Tonga": "汤加王国",
      "Timor-Leste": "东帝汶",
      "Togo": "多哥",
      "Trinidad and Tobago": "特立尼达和多巴哥",
      "Tunisia": "突尼斯",
      "Turkey": "土耳其",
      "Turkmenistan": "土库曼斯坦",
      "Uganda": "乌干达",
      "Ukraine": "乌克兰",
      "United Arab Emirates": "阿拉伯联合酋长国",
      "United Kingdom": "大不列颠联合王国",
      "United Republic of Tanzania": "坦桑尼亚联合共和国",
      "United States": "美国",
      "United States of America": "美利坚合众国",
      "Uruguay": "乌拉圭",
      "Uzbekistan": "乌兹别克斯坦",
      "Vanuatu": "瓦努阿图",
      "Venezuela": "委内瑞拉",
      "Vietnam": "越南",
      "West Bank": "西岸",
      "W. Sahara": "西撒哈拉",
      "Yemen": "也门",
      "Zambia": "赞比亚",
      "Zimbabwe": "津巴布韦"
    },
    
    };
   
  
  },
  
  created() {
    this.getdata()
  },
  mounted() {
   
    this.showmap();
  },
  watch: {},
  methods: {
    
          findKey(obj, value, compare = (a, b) => a === b) {
    return Object.keys(obj).find(k => compare(obj[k], value))

},

    getdata(){
  request({
        url: "/apt/vendorssearch",
        params: {
          bb: '',
          startDate: '',
          endDate: '',
          securityVendorCountry: '',
          securityRevealCountry: '',
          securityVendorName: '',
          page: 1,
        },
      }).then((res) => {
        
        console.log(res.data.data,'xsss')
      
     
 
  for (let item of res.data.data){


if ((this.mappoint[this.findKey(this.nammap,item.aptfromcountry)]!==undefined)&& (this.mappoint[this.findKey(this.nammap,item.securityVendorCountry)]!==undefined)){
    // console.log(this.mappoint[findKey(this.nammap,item.aptfromcountry)])
    this.linedata.push(
        {coords: [
                  this.mappoint[this.findKey(this.nammap,item.aptfromcountry)],
                  this.mappoint[this.findKey(this.nammap,item.securityVendorCountry)],
                ],
                lineStyle: { color: "#ffff00" },
              },
    )}
  } 
  console.log(this.linedata)
  this.showmap()
  
  
  

  



      })//这里暂时展示的是安全公司所属国家和apt所属国家的数据

     request({

url: "/apt/sourceCountry"

}).then((res)=>{ 
  
  this.aptcountry=res.data.data
  console.log(this.aptcountry)
  this.showmap()
 
 }) 

    },

    showmap() {
      
      this.map = this.$echarts.init(document.getElementById("map"));

      this.map.showLoading();
      this.$echarts.registerMap("world", worldmapjson);
      this.map.hideLoading();
      let option = {
        visualMap: {
          left: "left",
         // continuous 类型为连续型  piecewise 类型为分段型
          show: false, // 是否显示 visualMap-continuous 组件 如果设置为 false，不会显示，但是数据映射的功能还存在
          // 指定 visualMapContinuous 组件的允许的最小/大值。'min'/'max' 必须用户指定。
          // [visualMap.min, visualMax.max] 形成了视觉映射的『定义域』
          min: 0,
          max: 100,
          // 文本样式
          textStyle: {
            fontSize: 14,
            color: '#035cf5',
          
          },
          realtime: true, // 拖拽时，是否实时更新
          text: ["High", "Low"],
          calculable: true, // 是否显示拖拽用的手柄
          // 定义 在选中范围中 的视觉元素
          type: 'piecewise', // 类型为分段型
          top: "bottom",
          right: 5,
          splitNumber: 6,// 图元数量
          seriesIndex: [0],
          itemWidth: 20, // 每个图元的宽度
          itemGap: 2,    // 每两个图元之间的间隔距离，单位为px
          pieces: [      // 自定义每一段的范围，以及每一段的文字
            { gte: 51, label: '51以上', color: '#035cf5' }, // 不指定 max，表示 max 为无限大（Infinity）。
            { gte: 31, lte: 50, label: '31-50', color: '#3375e4' },
            { gte: 10, lte: 30, label: '10-30', color: '#6797ef' },
            { gte: 6, lte: 9, label: '6-9', color: '#7D7DFF' },
            { gte: 3, lte: 5, label: '3-5', color: '#46A3FF' },
            { gte:1,lte: 2, label: '1-2', color: '#D2E9FF' }          // 不指定 min，表示 min 为无限大（-Infinity）。
          ],
          showLabel:true, 

        },
           tooltip: {
          trigger: 'item', // 触发类型, 数据项图形触发，主要在散点图，饼图等无类目轴的图表中使用
          // 提示框浮层内容格式器，支持字符串模板和回调函数两种形式
          // 使用函数模板  传入的数据值 -> value: number | Array
          formatter: function (val) {
            return '国家/地区:'+val.data.name +  '<br/>' +' APT组织数量:' + val.data.value
          }
        },
        backgroundColor: "",
        grid: {
          top: 0,
          bottom: 0,
          left: 0,
          right: 0,
        },
        geo: {
          map: "world",

          aspectScale: 0.75, //长宽比
          zoom: 1,
          roam: false, //缩放

         
            itemStyle: {
              normal: {
                borderColor: "rgb(147, 235, 248)",
                borderWidth: 1,
                areaColor: {
                  type: "radial",
                  x: 0.5,
                  y: 0.5,
                  r: 0.8,
                  colorStops: [
                    {
                      offset: 0,
                      color: "#09132c", // 0% 处的颜色
                    },
                    {
                      offset: 1,
                      color: "#274d68", // 100% 处的颜色
                    },
                  ],
                  globalCoord: true, // 缺省为 false
                },
              },
              emphasis: {
                areaColor: "rgb(46,229,206)",
                //    shadowColor: 'rgb(12,25,50)',
                borderWidth: 0.1,
              },
            },
        },
        series: [
          {
            type: "map",
             map: 'world', 
        // geoIndex: 0,
            roam: false,
            
            label: {
              normal: {
                show: false,
                textStyle: {
                  color: "#1DE9B6",
                },
              },
              emphasis: {   //鼠标移入动态的时候显示的默认样式
                textStyle: {
                  color: "rgb(183,185,14)",
                },
              },
            },

            itemStyle: {
              normal: {
                borderColor: "rgb(147, 235, 248)",//地图轮廓线
                borderWidth: 1,
                areaColor: {
                  type: "radial",
                  x: 0.5,
                  y: 0.5,
                  r: 0.8,
                  colorStops: [
                    {
                      offset: 0,
                      color: "#09132c", // 0% 处的颜色
                    },
                    {
                      offset: 1,
                      color: "#274d68", // 100% 处的颜色
                    },
                  ],
                  globalCoord: true, // 缺省为 false
                },
              },
              emphasis: {
                areaColor: "#FF0000",
                //    shadowColor: 'rgb(12,25,50)',
                borderWidth: 0.1,
              },
            },
            // zoom: 1.1,
            //roam: false,
            // map: "china", //使用
             data: this.aptcountry,//待传入动态数据
             nameMap: this.nammap,

            // data: this.difficultData //热力图数据   不同区域 不同的底色
          },
          {
            type: "lines",
            zlevel: 2,
            effect: {
              show: true,
              period: 4, //箭头指向速度，值越小速度越快
              trailLength: 0.4, //特效尾迹长度[0,1]值越大，尾迹越长重
              symbol: "arrow", //箭头图标
              symbolSize: 7, //图标大小
            },
            lineStyle: {
              normal: {
                color: "#1DE9B6",
                width: 1, //线条宽度
                opacity: 0.1, //尾迹线条透明度
                curveness: 0.3, //尾迹线条曲直度
              },
            },
            data: this.linedata
          },
        ],
      };

      this.map.setOption(option, true);
    },
  },
};
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
</style>
